<script>
init({
  title: 'Column Events',
  desc: 'Use `events` column option to define the events for the formatter column.',
  links: ['bootstrap-table.min.css'],
  scripts: ['bootstrap-table.min.js']
})
</script>

<template>
  <table
    id="table"
    data-toggle="table"
    data-height="460"
    data-url="json/data1.json"
  >
    <thead>
      <tr>
        <th data-field="id">
          ID
        </th>
        <th data-field="name">
          Item Name
        </th>
        <th data-field="price">
          Item Price
        </th>
        <th
          data-field="operate"
          data-formatter="operateFormatter"
          data-events="operateEvents"
        >
          Item Price
        </th>
      </tr>
    </thead>
  </table>
</template>

<script>
  const $table = $('#table')

  window.operateFormatter = () => [
    '<a class="like" href="javascript:void(0)" title="Like">',
    '<i class="fa fa-heart"></i>',
    '</a>  ',
    '<a class="remove" href="javascript:void(0)" title="Remove">',
    '<i class="fa fa-trash"></i>',
    '</a>'
  ].join('')

  window.operateEvents = {
    'click .like': (e, value, row) => {
      alert(`You click like action, row: ${JSON.stringify(row)}`)
    },
    'click .remove': (e, value, row) => {
      $table.bootstrapTable('remove', {
        field: 'id',
        values: [row.id]
      })
    }
  }
</script>
